<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Account extends LAT_Controller {

	public function __construct() {
		$this->lang->load("account");
	}

	public function index() {
		$this->load->view('echo', array('data'=> 'This function has not been made yet.'));
	}

	public function register() {

		$this->load->library('validate');
		$form = array(
				'email'            => array('label' => $this->lang->line('email_address'), 'minimum' => 1, 'maximum' => 255, 'type' => 'email', 'regex' => array('email'))
			,	'name'             => array('label' => $this->lang->line('display_name'), 'minimum' => 2, 'maximum' => 25)
			,	'password'         => array('label' => $this->lang->line('password'), 'minimum' => 6, 'type' => 'password', 'regex' => array('password'), 'msg' => 'Needs a non-alphabetical character')
			,	'confirm-password' => array('label' => $this->lang->line('confirm-password'), 'minimum' => 6, 'type' => 'password', 'match' => 'password')
			,	'captcha'          => array('label' => $this->lang->line('captcha'), 'type'=> 'captcha')
		);

		if($this->input->post('submit')) {

			$this->load->model('account_func');
			$this->layout->data = array();
			$result = $this->validate->run($form);

			if($result['success'] === true) {
				$result = $this->account_func->create_user(array(
						'email'    => $this->input->post('email')
					,	'name'     => $this->input->post('name')
					,	'password' => $this->input->post('password')
					,	'ip'       => $this->input->ip_address()
				));
			}

			$this->layout->data = array_merge($this->layout->data, $result);

			if($result['success'] === true) {
				$this->layout->redirect($this->store->data('vars', 'index'));
				$this->layout->success_message($this->lang->line('registration_successful'));
			}

		} else {

			$this->load->helper('form');
			$this->validate->parse($form);
			$this->layout->add_js_file("account.js");
			$this->load->view('account/register', array(
					'terms' => $this->store->data('setting', 'terms')
				,	'form'  => $form
			));

		}
	}
}

/* End of file account.php */
/* Location: ./application/controllers/account.php */